package com.example.toutiao.ui.main.adpater

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import cn.jzvd.JzvdStd
import com.example.toutiao.R
import com.example.toutiao.ui.main.model.VideoModel
import com.example.toutiao.utils.ImageLoaderUtils

class VideoAdapter(videoList:MutableList<VideoModel>):RecyclerView.Adapter<VideoAdapter.VideoHolder>() {
    private  var videoList:MutableList<VideoModel>?=videoList

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VideoHolder =VideoHolder(
        LayoutInflater.from(parent.context).inflate(R.layout.item_video,parent,false))

    override fun onBindViewHolder(holder: VideoHolder, position: Int) {
        if(videoList!=null){
            val videoModel:VideoModel= videoList!![position]
            holder.video.tinyBackImageView.visibility=View.GONE
            holder.video.setUp(videoModel.src,videoModel.title)
            ImageLoaderUtils.loadRoundImage(holder.itemView.context,videoModel.cover,holder.video.thumbImageView)
            ImageLoaderUtils.loadRoundImage(holder.itemView.context,videoModel.avatar,holder.avatar)
            holder.playNum.text="${videoModel.playNum} 播放量"
            holder.likeNum.text="${videoModel.likeNum}"
            holder.durationNum.text="${videoModel.duration}"
            holder.author.text="${videoModel.author}"

        }
    }

    override fun getItemCount(): Int =videoList!!.size
    class VideoHolder(it:View) :RecyclerView.ViewHolder(it){
        var playNum:TextView=it.findViewById(R.id.tv_video_num)
        var durationNum:TextView=it.findViewById(R.id.tv_duration)
        var likeNum:TextView=it.findViewById(R.id.tv_video_like)
        var video: JzvdStd =it.findViewById(R.id.js_video)
        var avatar: ImageView =it.findViewById(R.id.tv_avatar)
        var author: TextView =it.findViewById(R.id.tv_video_name)

    }
}